storBattery = new Vue({
	el: "#storBattery",
	data: {
		currentUser:'', // 当前用户信息
		batteryTypeList: [], // 电池类型
		batteryGroupList: [], // 电池组别
		storageBattery: '', // 合并蓄电池用于前台展示
		testStaffCodeName: '',//测试人编号姓名
		tutelageStaffCodeName: '',//监护人编号姓名
		time: '',//合并测量时间用于前台展示
		parentObject: {}, // 前一个页面传参
		active: "", // 当前节点
		workType: '', // 流程类型
		isView: false, // 是否可编辑
		isSaveVisable: false,//是否显示保存按钮
		isSubVisable: false,//是否显示提交按钮
		isBackVisable: false,//是否显示退回按钮
		isConfVisable: false,//是否显示确认按钮
		isPassVisable: false,//是否显示通过按钮
		batteryForm: {
			storbatteryCheckId: '',//蓄电池测量记录主键
			workId: '',//工作主键
			workDesc: '',//工作描述
			testStaffCode: '',// 测试人编号
			testStaffName: '',//测试人姓名
			tutelageStaffCode: '',//监护人编号
			tutelageStaffName: '',//监护人姓名
			begTime: '',//测量时间起
			endTime: '',//测量时间止
			storageBatteryType: '',// 蓄电池类型
			storageBatteryGroup: '',//蓄电池组别
			storageBatteryCount: '',//电池数量
			acVoltage: '',//交流电压
			acCurrent: '',//交流电流
			voltageLowerLimit: '',//标准电压下限
			voltageUpperLimit: '',//标准电压上限
			temperature: '',//温度
			busVoltage: '',//母线电压
			chargingCurrent: '',//充电电流
			roomTemperature: '',//室温
			measureVoltage: [],//测量电压,json形式保存
			measureResult: '',//测量结果 0:异常 1:正常
			abnormalBatteryCode: [],//问题电池编号,逗号分隔
			measureDesc: '',//测量结论
			remark: '',//备注
			client: '',//客户ID
			dataSource: 'NEIOS_APP'+localStorage.getItem("currVersion"),//数据来源
			status: '',//业务状态
			dataStatus: '',//是否有效 参见码表0删除&1正常
			createBy: '',//创建人员
			createStaffName: '',//创建人姓名
			createDate: '',//创建时间
			modifyBy: '',//修改人员
			modifyStaffName: '',//修改人员姓名
			modifyDate: '',//修改时间
		},
		
		questionArrary: [],//缺陷记录
		isShow: false,
		showCheck: false,//显示审批人
		showDes: true,//显示意见框
		backOrAgree: '',//点击通过还是退回打开弹窗
		submitSwitch: {
			questionArrary: [],
			confirmPerson: '',
			desc: '',
			confirmPersonCode: [],
			confirmPersonName: [],
			strCode: '',
			strName: ''
		},
		submitParams:'',
	},
	components:{
		processlog, // 流程日志	
	},
	created: function() {
		let _this = this
		_this.currentUser = JSON.parse(localStorage.getItem("neiosUser"))
		_this.parentObject = JSON.parse(localStorage.getItem("neiosGoDetail")).obj
		// 获取码表
		let dictCodes = 'BATTERY_TYPE,STORBATTARY_GROUP_TYPE';
		mui.neiosCommon.queryDict(dictCodes,function(data){
			if (data != '') {
				_this.batteryTypeList = data.BATTERY_TYPE 
				_this.batteryGroupList = data.STORBATTARY_GROUP_TYPE
				_this.queryDetail() // 查询详情
			}
		})
	},
	methods: {
		// 查询详情
		queryDetail () {
			let _this = this
			let param = {
				workId:this.parentObject.workId
			}
			mui.neiosRequst.httpRequst('/app/regularWork/neiosStorbatteryCheck/queryStorbatteryRecord', param,
				function(data) {
					if (data.code == '0') {
						_this.batteryForm = JSON.parse(JSON.stringify(data.data));
						if (data.data.measureVoltage == null || data.data.measureVoltage == '') {
							_this.batteryForm.measureVoltage = [];
						} else {
							_this.batteryForm.measureVoltage = JSON.parse(data.data.measureVoltage);
						}
						if (data.data.abnormalBatteryCode == null || data.data.abnormalBatteryCode == '') {
							_this.batteryForm.abnormalBatteryCode = [];
						} else {
							_this.batteryForm.abnormalBatteryCode = data.data.abnormalBatteryCode.split(',');
						}
						
						if (_this.active == '20') {
							_this.batteryForm.testStaffCode = _this.currentUser["userId"];
							_this.batteryForm.testStaffName = _this.currentUser["name"];
							_this.testStaffCodeName = _this.currentUser["userName"];
							if (data.data.testStaffCode.toUpperCase() != _this.currentUser["userId"].toUpperCase()) {
								_this.batteryForm.tutelageStaffCode = data.data.testStaffCode;
								_this.batteryForm.tutelageStaffName = data.data.testStaffName;
								_this.tutelageStaffCodeName = `[${data.data.testStaffCode}]${data.data.testStaffName}`;
							} else {
								_this.batteryForm.tutelageStaffCode = data.data.tutelageStaffCode;
								_this.batteryForm.tutelageStaffName = data.data.tutelageStaffName;
								_this.tutelageStaffCodeName = `[${data.data.tutelageStaffCode}]${data.data.tutelageStaffName}`;
							}
						} else {
							_this.testStaffCodeName = `[${data.data.testStaffCode}]${data.data.testStaffName}`;
							_this.tutelageStaffCodeName = `[${data.data.tutelageStaffCode}]${data.data.tutelageStaffName}`;
						}
						// _this.testStaffCodeName = `[${data.data.testStaffCode}]${data.data.testStaffName}`;
						// _this.tutelageStaffCodeName = `[${data.data.tutelageStaffCode}]${data.data.tutelageStaffName}`;
						if (data.data.endTime == null || data.data.endTime == '') {
							_this.batteryForm.endTime = mui.neiosCommon.transTime(new Date());
						}
						_this.batteryForm.begTime = _this.batteryForm.begTime.replace(/-/g, '/');
						_this.batteryForm.endTime = _this.batteryForm.endTime.replace(/-/g, '/');
						let newBegTime = mui.neiosCommon.transTime(new Date(_this.batteryForm.begTime),'day');
						let newEndTime = mui.neiosCommon.transTime(new Date(_this.batteryForm.endTime),'day');
						_this.time = `${newBegTime}~${newEndTime}`;
						let bType;
						_this.batteryTypeList.map(v => {
							if (_this.batteryForm.storageBatteryType == v.itemValue) {
								bType = v.itemText;
							} 
						});
						let bGroup;
						_this.batteryGroupList.map(va => {
							if (_this.batteryForm.storageBatteryGroup == va.itemValue) {
								bGroup = va.itemText;
							}
						});
						_this.storageBattery = `${bType}-${bGroup}`;
						if (data.data.storageBatteryCount == null || data.data.storageBatteryCount == '') {
							_this.queryIsFirst(_this.batteryForm.storageBatteryType, _this.batteryForm.storageBatteryGroup);
						} else {
							_this.batteryForm.storageBatteryCount = data.data.storageBatteryCount.toString();
						}
					} else {
						mui.toast('获取数据失败,请稍后再试！')
					}
				},
				function() {
					mui.toast('获取数据失败,请稍后再试！')
				}
			);
		},
		// 查询蓄电池组是否为第一次测量
		queryIsFirst (type, group) {
			let _this = this;
			let params = {
				storageBatteryType: type,
				storageBatteryGroup: group,
				stationCode: localStorage.getItem('neiosStationCode'),
			}
			mui.neiosRequst.httpRequst('/app/regularWork/neiosStorbatteryCheck/queryStorbatteryIsFirst', params,
				function(result) {
					if (result.code == '0') {
						 //如果是第一次，测量数量给默认值，不是第一次，测量数量给上一次的数量
						if (result.isFirst == true) {
							if (type == '1') {
								_this.batteryForm.storageBatteryCount = '103';
							} else {
								_this.batteryForm.storageBatteryCount = '24';
							}
							_this.createInput();
						} else {
							_this.batteryForm.storageBatteryCount = result.count;
							_this.createInput();
							_this.batteryForm.voltageLowerLimit = result.lower;
							_this.batteryForm.voltageUpperLimit = result.upper;
						}
					} else {
						mui.toast('查询列表失败，请稍后重试！')
					}
				},
				function() {
					mui.toast('查询列表失败，请稍后重试！')
				}
			);
		},
		//生成测量需要的input框
		createInput: function () {
			let _this = this;
			_this.batteryForm.measureDesc = '';
			_this.batteryForm.measureVoltage = []
			for (let i = 0; i < _this.batteryForm.storageBatteryCount; i++) {
				_this.batteryForm.measureVoltage.push({ voltage: '2.22_' });
			}
		},
		// 返回
		goBack () {
			mui.back()
		}
	}
});